package ningbo.pet;

import java.lang.annotation.ElementType;
import java.util.Random;
import java.util.Scanner;

/**
 * @Author 宁铂
 * @Date 2021/7/14 20:14
 * @Version 1.0
 */
public class TestPet {
    public static void main(String[] args) {
        System.out.println("请选择猫或者狗");
        System.out.println("1：猫");
        System.out.println("2：狗");
        System.out.println("请选择数字：>");
        int c = new Scanner(System.in).nextInt();
        System.out.println("请给你的动物起名字：");
        String n = new Scanner(System.in).nextLine();

        Cat cat = null;
        Dog dog = null;

        if(c == 1){
            cat = new Cat(n);
            play(cat);
        }else{
            dog = new Dog(n);
            play(dog);
        }
    }

    private static void play(Cat cat){
        System.out.println("按回车继续");
        while (true){
            new Scanner(System.in).nextLine();
            int r = new Random().nextInt(5);
            switch (r){
                case 0:cat.play();break;
                case 2:cat.feed();break;
                default:cat.punish();break;
            }
        }
    }

    private static void play(Dog dog){
        System.out.println("按回车继续");
        while (true){
            new Scanner(System.in).nextLine();
            int r = new Random().nextInt(5);
            switch (r){
                case 0:dog.play();break;
                case 2:dog.feed();break;
                default:dog.punish();break;
            }
        }
    }
}
